<%- include('../layout/header.ejs') %>
<link rel="stylesheet" href="../../public/css/mditor.min.css">
<script src="../../public/js/mditor.min.js"></script>
<div class="container">
    <h1>文章编辑页</h1>
    <hr>
    <form id="form">
        <!-- 获取作者id 的隐藏域 -->
        <input type="hidden" name="id" value="<%=article.id%>">
        <div class="form-group">
            <label for="">文章标题:</label>
            <input type="text" name="title" class="form-control" required value="<%= article.title %>">
        </div>

        <div class="form-group">
            <label for="">文章内容:</label>
            <textarea name="content" class="form-control" id="editor">
                <%= article.content %>
            </textarea>
        </div>

        <div class="form-group">
                <input type="submit" value="编辑完成" class="btn btn-primary">
            </div>
    </form>

</div>


<%- include('../layout/footer.ejs') %>
<script src="../../public/jquery.min.js"></script>
<script>
    $(function () {
        var mditor = Mditor.fromTextarea(document.getElementById('editor'));  
        $('#form').on('submit',function(){
            $.ajax({
            url:'/article/adit',
            type:'post',
            dataType:'json',
            data:$('#form').serialize(),
            success:(res) => {
                if(res.status !==200) return alert('修改文章失败')
                location.href = '/article/info/<%= article.id %>'
            }
        }) 
        })
    })
</script>